package org.pearl.spring.demo.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

/**
 * Created by TD on 2021/10/9
 */
@Service
@PropertySource("classpath:application.properties")
@Component
public class UserService {

    // @Autowired(required = false)

    @Resource(name = "userDaoImplOne")
    private UserDao userDao;

    @Value("${name}")
    private String name;

    public void selectUser() {
        System.out.println(name);
        userDao.select();
    }

    @PostConstruct
    public void postConstruct() {
        System.out.println("初始化回调");
    }

    @PreDestroy
    public void preDestroy() {
        System.out.println("销毁回调");
    }
/*    @Autowired
    public UserService( @Qualifier("userDaoImplOne") UserDao userDao) {
        this.userDao = userDao;
    }*/



   /* @Autowired
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }*/

    /*@Autowired
    public void test(UserDao userDao) {
        this.userDao = userDao;
    }*/
}
